<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title>Wealth Management Online</title>
		<%= stylesheet_link_tag '/ext-2.0/resources/css/ext-all' %>
		<style>
			.accesskey {
				text-decoration: underline;
			}
		</style>
		<%= javascript_include_tag '/ext-2.0/adapter/ext/ext-base' %>
		<%= javascript_include_tag '/ext-2.0/ext-all' %>
		<%= javascript_include_tag '/ext-2.0/build/locale/ext-lang-zh_CN' %>
		<%= javascript_include_tag 'Ext/ux/LocalComboBox' %>
		<%= javascript_include_tag 'application' %>
		<%= javascript_include_tag 'wol-lang-zh_CN' %>
		<script type="text/javascript">
			Ext.onReady(function() {
				applyLocaleForEntities();
				
				Wol.VIEWPORT = new Ext.Viewport({
					items: {
						bodyStyle: 'padding: 10px 20px 0',
						buttons: [
							button(Wol.entity.BUTTONS.window.save, function() {
								submit(function() {
									if(window.opener) {
										var tab = window.opener.Ext.getCmp('tab-entities');
										
										if(tab) {
											tab.items.each(function(item) {
												if(item.rendered) {
													item.getStore().load();
												}
											});
										}
									}
									
									window.close();
								}<% if params[:id] %>, 'PUT'<% end %>);
							}, { formBind: true, id: 'btn-83' }),
							button(Wol.entity.BUTTONS.window.reset,  reset, { id: 'btn-82' }),
							button(Wol.entity.BUTTONS.window.cancel, function() { window.close(); }, { id: 'btn-67' })
						],
						items: [{
							defaults: {
								baseCls: 'x-plain',
								columnWidth: .5,
								defaults: { anchor: '93%' },
								defaultType: 'textfield',
								layout: 'form'
							},
							items: [{
								items: [
									{ fieldLabel: Wol.entity.FIELDS.type,    name: 'entity[type]',    tabIndex: 1, allowBlank: false, data: [ Wol.entity.TYPES.institution, Wol.entity.TYPES.individual ],<% if params[:id]%> disabled: true,<% else %> value: window.opener.Ext.getCmp('tab-entities').getActiveTab().initialConfig.type || Wol.entity.TYPES.institution[1],<% end %> xtype: 'localcombo' },
									{ fieldLabel: Wol.entity.FIELDS.url,     name: 'entity[url]',     tabIndex: 3, vtype: 'url' },
									{ fieldLabel: Wol.entity.FIELDS.phone,   name: 'entity[phone]',   tabIndex: 5 },
									{ fieldLabel: Wol.entity.FIELDS.address, name: 'entity[address]', tabIndex: 7 }
								]
							}, {
								items: [
									{ fieldLabel: Wol.entity.FIELDS.name,  name: 'entity[name]',  tabIndex: 2, allowBlank: false, maxLength: 10 },
									{ fieldLabel: Wol.entity.FIELDS.email, name: 'entity[email]', tabIndex: 4, vtype: 'email' },
									{ fieldLabel: Wol.entity.FIELDS.fax,   name: 'entity[fax]',   tabIndex: 6 },
									{ fieldLabel: Wol.entity.FIELDS.zip,   name: 'entity[zip]',   tabIndex: 8 }
								]
							}],
							layout: 'column',
							title: Wol.entity.TITLE
						}, {
							items: { anchor: '98%', autoHeight: true, hideLabel: true, name: 'entity[remark]', tabIndex: 9, xtype: 'htmleditor' },
							title: Wol.entity.FIELDS.remark
						}],
						keys: {
							alt: true,
							handler: function(key) {
								var button = Ext.getCmp('btn-' + key);
								
								if(!button.disabled) {
									button.handler.call();
								}
							},
							key: 'src'
						},
						labelWidth: 55,
						url: '.',
						xtype: 'form'
					}
				})
<% if params[:id] -%>
				
				load();
<% end -%>
			});
		</script>
	</head>
</html>
